home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / B_SEARCH.CPP < prev    next >
Text File  |  1997-05-06  |  732b  |  30 lines

  1.  #include <vector>
  2.  #include <algorithm>
  3.  
  4.  using namespace std;
  5.  
  6.  int main ()
  7.  {
  8.    typedef vector<int>::iterator iterator;
  9.    int d1[10] = {0,1,2,2,3,4,2,2,6,7};
  10.    //
  11.    // Set up a vector.
  12.    //
  13.    vector<int> v1(d1+0, d1+10);
  14.    //
  15.    // Try binary_search variants.
  16.    //
  17.    bool b1 = binary_search(v1.begin(),v1.end(),3);
  18.    bool b2 = binary_search(v1.begin(),v1.end(),11,less<int>());
  19.    //
  20.    // Output results.
  21.    //
  22.    cout << "In the vector: ";
  23.    copy(v1.begin(),v1.end(), ostream_iterator<int>(cout," "));
  24.    cout << endl << "The number 3 was "
  25.         << (b1 ? "FOUND" : "NOT FOUND");
  26.    cout << endl << "The number 11 was "
  27.         << (b2 ? "FOUND" : "NOT FOUND") << endl;
  28.    return 0;
  29.  }
  30.